home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Complementary Applications 2004 May / SGI IRIX 6.5 Complementary Applications 2004 May.iso / dist / OpenOffice.idb / usr / OpenOffice / help / en / sbasic.jar / text / sbasic / common / 03080302.xml < prev    next >
Encoding:
Extensible Markup Language  |  2002-01-24  |  2.6 KB  |  44 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <html><head><title>Rnd Function [Runtime]</title><meta name="filename" content="text/sbasic/common/03080302"/><meta name="language" content="en-US"/><help:css-file-link xmlns:help="http://openoffice.org/2000/help"/><!--The CSS style header method for setting styles--><style type="text/css">
  3.  
  4.         p.P1{
  5.                 }
  6.         p.P2{
  7.                 }
  8.         span.T1{
  9.                 font-weight:bold;}
  10.         </style></head><body>
  11.   
  12.   
  13.   <help:to-be-embedded Eid="rnd" xmlns:help="http://openoffice.org/2000/help">
  14.   <p class="Head1"><help:link Id="66414">Rnd Function [Runtime]</help:link></p>
  15.   <p class="Paragraph">Returns a random number between 0 and 1.</p>
  16.   </help:to-be-embedded>
  17.   <p class="Paragraph"><span class="T1">Syntax</span>:</p>
  18.   <p class="Paragraph">Rnd [(Expression)] <help:key-word value="Rnd" tag="kw66414_1" xmlns:help="http://openoffice.org/2000/help"/></p>
  19.   <p class="Paragraph"><span class="T1">Return value</span>:</p>
  20.   <p class="Paragraph">Double</p>
  21.   <p class="Paragraph"><span class="T1">Parameter</span>:</p>
  22.   <p class="Paragraph">Expression: Any numeric expression that defines how random numbers will be generated.</p>
  23.   <p class="Paragraph">Less than zero: Always returns the same random number.</p>
  24.   <p class="Paragraph">Greater than zero: Returns the next random number in the sequence.</p>
  25.   <p class="Paragraph">Zero: Returns the random number last generated.</p>
  26.   <p class="Paragraph">Omitted: Returns the next random number in the sequence.</p>
  27.   <p class="Paragraph">If the same number is passed for each successive call to the Rnd function, the same random-number sequence is generated, because the Expression parameter is used as a starting point for the next number.</p>
  28.   <p class="Paragraph">The <span class="T1">Rnd</span> function only returns values ranging from 0 to 1. To generate random integers in a given range, use the formula in the following example:</p>
  29.   <p class="P2">Example:</p>
  30.   <p class="PropText">Sub ExampleRandomSelect</p>
  31.   <p class="PropText">Dim iVar As Integer</p>
  32.   <p class="PropText">iVar = Int((15 * Rnd) -2)</p>
  33.   <p class="PropText">Select Case iVar</p>
  34.   <p class="PropText">Case 1 To 5</p>
  35.   <p class="PropText">Print "Number from 1 to 5"</p>
  36.   <p class="PropText">Case 6, 7, 8</p>
  37.   <p class="PropText">Print "Number from 6 to 8"</p>
  38.   <p class="PropText">Case Is > 8 And iVar < 11</p>
  39.   <p class="PropText">Print "Greater than 8"</p>
  40.   <p class="PropText">Case Else</p>
  41.   <p class="PropText">Print "Outside range 1 to 10"</p>
  42.   <p class="PropText">End Select</p>
  43.   <p class="PropText">end sub</p>
  44.  </body></html>